package com.wanmait.movie.controller;
import com.wanmait.movie.service.ReplyService;
import com.wanmait.movie.util.AjaxResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("manage/reply")
public class ManageReplyController {
    @Resource
    ReplyService replyService;
    @GetMapping("list")
    public AjaxResult list(Integer pageNum, Integer commentsId, String keyword) {
        if (pageNum == null || pageNum == 0) {
            pageNum = 1;
        }
        System.out.println(commentsId);
        if (commentsId == null) {
            commentsId = 0;
        }
        if (keyword == null) {
            keyword = "";
        }
        return AjaxResult.success(replyService.getReplyList(pageNum, commentsId, keyword)).put("total", replyService.getReplyList(pageNum, commentsId, keyword).getTotal());
    }
    @GetMapping("delete")
    public AjaxResult delete(Integer id){
        if(!replyService.removeById(id)){
            return AjaxResult.error(506,"删除错误");
        }
        return AjaxResult.success(replyService.removeById(id));
    }
}
